﻿using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aixiu.DAL;

namespace AiXiu.BLL
{
    public class UsersBLL
    {

        AiXiuDbContent dbContent = new AiXiuDbContent();
        /// <summary>
        /// 通过用户编号查找
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public TBUsers FindByUserId(int userId)
        {
            return dbContent.TBUsers.SingleOrDefault(m => m.Id == userId);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public OperResult<TBUsers> GetUser(int userId)
        {
            UsersDAL userService = new UsersDAL();
            TBUsers user = userService.FindByUserId(userId);
            return OperResult<TBUsers>.Succeed(user);
        }
        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <returns></returns>
        UsersDAL usersDAL = new UsersDAL();
        public List<TBUsers> GetTBUsers()
        {
            return usersDAL.GetTBUsers();
        }

        public TBUsers get(int id)
        {
            return usersDAL.get(id);
        }
        /// <summary>
        /// 添加用户信息
        /// </summary>
        /// <returns></returns>
        public int Add(TBUsers users)
        {
            return usersDAL.Add(users);
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id)
        {
            return usersDAL.Delete(id);
        }
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="user">用户信息</param>
        /// <returns></returns>
        public OperResult<TBUsers> EditWithoutAvatar(TBUsers user)
        {
            try
            {
                TBUsers profileEntity = usersDAL.EditWithoutAvatar(user);
                return OperResult<TBUsers>.Succeed(profileEntity);
            }
            catch (Exception ex)
            {
                return OperResult<TBUsers>.Wrong(ex);
            }
        }
        /// <summary>
        /// 编辑头像
        /// </summary>
        /// <param name="user">用户信息</param>
        /// <returns></returns>
        public OperResult<TBUsers> EditAvatar(TBUsers user)
        {
            try
            {
                TBUsers profileEntity = usersDAL.EditAvatar(user);
                return OperResult<TBUsers>.Succeed(profileEntity);
            }
            catch (Exception ex)
            {
                return OperResult<TBUsers>.Wrong(ex);
            }
        }
    }
}
